package com.yangming.springboot.controller;

import com.yangming.springboot.base.ResultInfo;
import com.yangming.springboot.query.RoleQuery;
import com.yangming.springboot.service.RoleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "role")
public class RoleController extends BaseController {

    @Resource
    private RoleService roleService;

    @RequestMapping(value = "queryAllRole")
    @ResponseBody
    public List<Map<String, Object>> queryAllRole(Integer userId){
      return roleService.queryAllRole(userId);
    };

    @RequestMapping(value = "list")
    @ResponseBody
    public Map<String, Object> queryRoleByParams(RoleQuery roleQuery){
        return roleService.queryRoleByParams(roleQuery);
    }

    @RequestMapping(value = "index")
    public String index(){
        return "role/role";
    }

    @RequestMapping(value = "addGrant")
    @ResponseBody
    public ResultInfo addGrant(Integer[] mids, Integer roleId){
        ResultInfo resultInfo = new ResultInfo();
        roleService.addGrant(mids, roleId);
        return resultInfo;
    }
}
